package com.zst.springbootjsonintegrationdemo.converter;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;

import javax.persistence.AttributeConverter;
import java.util.Map;

public class MapToJsonStringConverter implements AttributeConverter<Map, String> {
    @Override
    public String convertToDatabaseColumn(Map map) {
        if (map == null) {
            return null;
        }
        return JSON.toJSONString(map);
    }

    @Override
    public Map convertToEntityAttribute(String s) {
        if (s == null) {
            return null;
        }
        return JSON.parseObject(s).toJavaObject(Map.class);
    }
}
